package com.atguigu.gulimail.product.web.controller;

import com.atguigu.gulimail.product.entity.CategoryEntity;
import com.atguigu.gulimail.product.service.CategoryService;
import com.atguigu.gulimail.product.web.Vo.Catelog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Autowired
    StringRedisTemplate redisTemplate;



    @Autowired
    CategoryService categoryService;

    @GetMapping({"/","/index"})
    public String indexPage(Model model){
        /**
         * TODO 查询所有一级分类
         */
        List<CategoryEntity> categorys= categoryService.getLevelOneCategorys();
        model.addAttribute("categorys",categorys);
        //视图解析器 会进行拼接 前缀:classpath:/templates/    后缀: .html
        return "index";
    }

    @ResponseBody //将response的值 以json的形式返回
    @GetMapping("/index/json/catalog.json")
    public Map<String, List<Catelog2Vo>> getCatalogJson(){



        Map<String, List<Catelog2Vo>> map=categoryService.getCatalogJson();
        return map;
    }

}
